<?php
/**
 * (jobs) sku更新后，校检sku是否泛欧
 */
namespace App\Jobs\Products;

use App\Models\Basics\AmazonAccount;
use App\Models\Basics\AmazonCountry;
use App\Models\Product\ProductAmazonSku;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class AmazonSkuUpRelate implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $fanEuKey;

    /**
     * AmazonSkuUpRelate constructor.
     * @param $fanEuKey
     */
    public function __construct($fanEuKey)
    {
        $this->fanEuKey = $fanEuKey;
    }

    /**
     * Execute the job.
     * @return void
     */
    public function handle()
    {
        $this->exeFillData($this->fanEuKey);
    }

    private function exeFillData($fanEuKey){
        $country = AmazonCountry::options(['fan_eu' => 1]);
        $countryIdsForFanEU = array_keys($country->toArray());
        $notInAccountId = AmazonAccount::$_notFanEu;
        foreach ($fanEuKey as $_fanEuKey){
            list($sellerSku,$childAsin,$fnSku) = explode('_',$_fanEuKey);
            ProductAmazonSku::upTimes($sellerSku,$childAsin,$fnSku,$countryIdsForFanEU,$notInAccountId);
        }
    }
}
